package org.dcarew.clearcase.wizards;


import org.dcarew.clearcase.CCPlugin;
import org.dcarew.clearcase.CCRepositoryProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.ui.IConfigurationWizard;
import org.eclipse.ui.IWorkbench;

/**
 * 
 * 
 * @author Devon Carew
 */
public class CCProjectSharingWizard extends Wizard implements IConfigurationWizard
{
    private IProject project;
    
    
    /**
     * 
     */
    public CCProjectSharingWizard()
    {
        setWindowTitle("Configure ClearCase Project");
        setDefaultPageImageDescriptor(CCPlugin.getImageDescriptor("wizban/share_wizban.gif"));
        
        setNeedsProgressMonitor(true);
    }





    @Override
    public void init(IWorkbench workbench, IProject project)
    {
        this.project = project;
    }





    @Override
    public void addPages()
    {
        addPage(new CCProviderWizardPage());
    }





    @Override
    public boolean performFinish()
    {
        try
        {
            CCRepositoryProvider.setSharing(project, null);
            
            return true;
        }
        catch (TeamException e)
        {
            ErrorDialog.openError(
                    null, 
                    "Error Adding ClearCase Provider", 
                    e.toString(), 
                    new Status(IStatus.ERROR, CCPlugin.PLUGIN_ID, e.toString(), e));
            
            CCPlugin.log(e);
            
            return false;
        }
    }
    
    class CCProviderWizardPage
        extends WizardPage
    {
        
        public CCProviderWizardPage()
        {
            super("ccProviderWizardPage");
            
            setTitle("ClearCase Team Provider");
            setDescription("Add the ClearCase team provider to the project.");
        }
        
        public void createControl(Composite parent)
        {
            Label label = new Label(parent, SWT.WRAP);
            label.setText("Click Finish to add the ClearCase team provider to this project.");
            
            setControl(label);
        }
    }
    
}
